import request from '@/utils/request'

// ==================== 商家订单接口 ====================

// 获取商家订单列表
export function getMerchantOrders(params) {
  return request({
    url: '/api/v1/merchant/orders/list',
    method: 'get',
    params: {
      pageNum: params.pageNum || 1,
      pageSize: params.pageSize || 10,
      status: params.status
    }
  })
}

// 获取商家订单详情
export function getMerchantOrderDetail(orderId) {
  return request({
    url: `/api/v1/merchant/orders/${orderId}`,
    method: 'get'
  })
}

// 商家发货
export function shipOrder(orderId, deliveryCompany, deliveryNo) {
  return request({
    url: `/api/v1/merchant/orders/${orderId}/ship`,
    method: 'post',
    params: {
      deliveryCompany,
      deliveryNo
    }
  })
}

// 商家审核退款申请
export function auditRefund(data) {
  return request({
    url: '/api/v1/merchant/orders/refund/audit',
    method: 'post',
    data
  })
}

// ==================== 管理员订单接口 ====================

// 获取平台所有订单列表
export function getAdminOrders(params) {
  return request({
    url: '/api/v1/admin/orders/list',
    method: 'get',
    params: {
      pageNum: params.pageNum || 1,
      pageSize: params.pageSize || 10,
      status: params.status,
      merchantId: params.merchantId,
      userId: params.userId,
      startTime: params.startTime,
      endTime: params.endTime
    }
  })
}

// 获取订单详情
export function getAdminOrderDetail(orderId) {
  return request({
    url: `/api/v1/admin/orders/${orderId}`,
    method: 'get'
  })
}

// 强制退款
export function forceRefund(orderId, reason) {
  return request({
    url: `/api/v1/admin/orders/${orderId}/force-refund`,
    method: 'post',
    params: { reason }
  })
}

// 强制取消订单
export function forceCancel(orderId, reason) {
  return request({
    url: `/api/v1/admin/orders/${orderId}/cancel`,
    method: 'post',
    params: { reason }
  })
}

// 获取订单统计信息
export function getAdminOrderStatistics(params) {
  return request({
    url: '/api/v1/admin/orders/statistics',
    method: 'get',
    params: {
      startTime: params.startTime,
      endTime: params.endTime
    }
  })
}
